/*
  Copyright (c) 2011, Mikheev Rostislav
  Copyright (c) 2011, FreshFarsh team

  Steel Engine source code is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/**
  @author Mikheev Rostislav <hacenator@gmail.com>
  @date 13.03.2011
  @brief OpenGL texture loader source file
*/

#ifndef _H_STEEL_TEXTURE
#define _H_STEEL_TEXTURE

#include <GL/glew.h>
#include "image.h"
#include "common.h"

namespace _STEEL_NAMESPACE {

#define DEF_FILTER GL_LINEAR

class Texture {
 public:
	// constructor
	Texture(); /// default constructor

	/**
   *   Create texture object and loadin image from file
   *   @param
   *       Image filename
	 */
	explicit Texture(const char * filename);

  /**
   * Default destructor
   */
	~Texture();

  /**
   * Loading image from file
   * @param
   *   Image filename
   * @return
   *   True if successfull, false otherwise
   */
	bool LoadFromFile(const char * filename);

  /**
   * Bind OpenGL texture
   */
	void Bind();

  /**
	 * Bind OpenGL texture with specified unit
   */
  void Bind(GLenum unit);

  // accesors
	/**
   * Set texture filter
   * @param
   *   Texture filter (GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST etc)
   */
  void set_filter(GLint filter) {
    _filter = filter;
  }

  /**
	 * Get current texture filter
   * @return
   *   Texture filter (GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST etc)
   */
  GLint filter() {
    return _filter;
  }

  /**
   * Get initial image width
   */
  GLsizei width() {
    return _width;
  }

  /**
   * Get initial image height
   */
  GLsizei height() {
    return _height;
  }

	private:
		bool CreateTexture(Image * image); /// Create OpenGl texture from jImage

		GLuint _handle; ///< opengl texture handle
		GLint _filter; ///< texture filter
		GLsizei _width; ///< texture width
		GLsizei _height; ///< texture height
};
}

#endif /* _H_STEEL_TEXTURE */
